/*
 * Created on 08/28/2012 - 1:33 AM
 */
package sembr.vtk.writer;

import vtk.vtkDataSet;
import vtk.vtkImageData;
import vtk.vtkPolyData;
import vtk.vtkXMLDataSetWriter;

/**
 * The <code>VtkXmlDataSetWriter</code> class gets the subclass 
 * <code>vtkPolyData</code> or <code>vtkImagaData</code> instance of 
 * <code>vtkDataSet</code> superclass and creates the appropriate XML file .vtp 
 * for <code>vtkPolyData</code> or .vti for <code>vtkImagaData</code>.
 * 
 * @author adriano
 */

public class VtkXmlDataSetWriter 
{   
    private vtkXMLDataSetWriter xmlDataSetWriter;
    private String fileExtension;
            
    public VtkXmlDataSetWriter(String fileName, vtkDataSet dataSet)
    {
        xmlDataSetWriter = new vtkXMLDataSetWriter();
        setFileExtensionByDataSet(dataSet);
        xmlDataSetWriter.SetFileName(fileName + fileExtension);
        xmlDataSetWriter.SetInput(dataSet);        
    }
    
    public VtkXmlDataSetWriter(VtkXmlDataSetWriter copy)
    {
        xmlDataSetWriter = copy.xmlDataSetWriter;
    }    
    
    public void writeFile()
    {        
        xmlDataSetWriter.SetDataModeToAscii();
        xmlDataSetWriter.Write();        
    }
    
    private void setFileExtensionByDataSet(vtkDataSet dataSet)
    {        
        if (dataSet instanceof vtkImageData) 
        {
            fileExtension = ".vti";
        }         
        else if (dataSet instanceof vtkPolyData) 
        {
            fileExtension = ".vtp";
        }   
        else
        {
            fileExtension = ".vtk";
        }
    }
}
